﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;

namespace WindowsForms_Logic_Questions_Generator
{
    class FormatModulator
    {
        public void createRtf(string[] testString, int font0, int font1, int font2, int font3, int font4, int font5, int font6, string appPath)
        {
            try
            {
                string newLine = "\\line";
                string beginningOfstringCenter = " \\viewkind4\\uc1\\pard\\ltrpar\\qc\\f0\\fs";
                string beginningOfstring = " \\viewkind4\\uc1\\pard\\ltrpar\\ql\\f0\\fs";
                string beginningofQ1 = "{\\rtlch\\fcs1 \\af39\\afs24 \\ltrch\\fcs0 \\f39\\fs"; //"{\\ltrch\\fcs1 \\af39\\afs24 \\rtlch\\fcs0 \\f39\\fs";

                string beginningofQ2 = "\\insrsid5701769 \\hich\\af39\\dbch\\af31505\\loch\\f39";//"\\insrsid9524018 \\hich\\af39\\dbch\\af31505\\loch\\f39 ";
                string beginningOfstringRight = " \\viewkind4\\uc1\\pard\\ltrpar\\qr\\f0\\fs";
                string endOfstring = "\\f1\\rtlch\\par\\pard";
                int newfont;
                string newstring;

                System.IO.TextWriter writeFile = new StreamWriter(appPath);
                writeFile.Write("{\\rtf1\\fbidis\\ansi\\ansicpg1255\\deff0\\deflang1037{\\fonttbl{\\f0\\fnil\\fcharset0  arial;}{\\f1\\fnil\\fcharset177 arial;}}");
                
                // date
                newfont = font0 * 2;
                newstring = beginningOfstringRight + newfont.ToString() + " " + testString[0] + endOfstring;
                writeFile.Write(newstring);
                
                //name
                newfont = font2 * 2;
                newstring = beginningOfstring + newfont.ToString() + " " + testString[2] + newLine + endOfstring;
                writeFile.Write(newstring);

                newfont = font1 * 2;
                newstring = beginningOfstringCenter + newfont.ToString() + " " + testString[1] + newLine + endOfstring;
                writeFile.Write(newstring);
                
                newfont = font3 * 2;
                newstring = beginningOfstring + newfont.ToString() + " " + testString[3] + newLine + endOfstring;
                writeFile.Write(newstring);
                
                newfont = font4 * 2;
                newstring = beginningofQ1 + newfont.ToString() +beginningofQ2 + " " + testString[4] + newLine + endOfstring + "}";
                writeFile.Write(newstring);
                                
                newfont = font5 * 2;
                newstring = beginningOfstring + newfont.ToString() + " " + testString[5] + newLine + endOfstring;
                writeFile.Write(newstring);

                newfont = font6 * 2;
                newstring = beginningOfstring + newfont.ToString() + " " + testString[6] + newLine + endOfstring;
                writeFile.Write(newstring);
                
                writeFile.Write("}");
                writeFile.Flush();
                writeFile.Close();

                writeFile = null;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: Could not create rtf file : " + ex.Message);
            }


        }
    }
}
